package com.easybacklog.client.sourcefeatures;

import com.easybacklog.client.EasyBacklogGlobalVariables;
import com.easybacklog.client.LiveDocumentationHelpIcon;
import com.easybacklog.client.cucumberfeatures.ButtonRefresh;
import com.easybacklog.client.utilities.LoadingPanel;
import com.easybacklog.client.webservices.subversion.RequestUpdateSubversionSpecificationFile;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * 
 * @Feature
 */
public class SourceFeaturesView extends VerticalPanel {

	public static VerticalPanel vpSourceFeatures = new VerticalPanel();

	public SourceFeaturesView() {

		this.clear();

		this.setSpacing(20);

		this.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		HorizontalPanel hp2 = new HorizontalPanel();

		hp2.setSpacing(4);

		HTML html = new HTML(
				"<b><font color='blue' size='3'>Source Features</font></b> ");
		hp2.add(html);

		Label space = new Label(" ");
		space.setWidth("300px");
		hp2.add(space);

		hp2.add(new ButtonRefresh(buttonRefreshClickHandler()));

		hp2.add(new LiveDocumentationHelpIcon("easybacklog"));

		this.add(hp2);

		vpSourceFeatures.clear();

		vpSourceFeatures
				.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		if (EasyBacklogGlobalVariables.sourceFeatures != null) {

			vpSourceFeatures.add(new SourceFeaturesList());
		} else {

			vpSourceFeatures.add(new LoadingPanel());
		}

		this.add(vpSourceFeatures);
	}

	private ClickHandler buttonRefreshClickHandler() {

		return (new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				RequestUpdateSubversionSpecificationFile
						.sendPostRequest(EasyBacklogGlobalVariables.currentProject);

				SourceFeaturesView.vpSourceFeatures.clear();
				SourceFeaturesView.vpSourceFeatures
						.add(new SourceFeaturesList());
			}
		});

	}
}
